package test.hibernate.dao;

import java.util.Properties;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * Generated at Thu Feb 25 19:39:58 CET 2010
 *
 * @author Salto-db Generator v1.0.16 / EJB3 + Hibernate DAO
 */
public final class HibernateUtil {

	private static SessionFactory sessionFactory;
	
	public static Properties props = new Properties();

	static {
		try {
	                buildSessionFactory();
		} catch (Throwable ex) {

			throw new ExceptionInInitializerError(ex);
		}
	}

	private HibernateUtil() {

	}
	
	public static void buildSessionFactory(Properties properties) {
	        for (Object key : properties.keySet()) {
                        props.setProperty(key.toString(), properties.getProperty(key.toString()));
                }
	}

        public static void buildSessionFactory() {
                AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration();
                annotationConfiguration.addProperties(props);
                
                annotationConfiguration.configure();
                
                sessionFactory = annotationConfiguration.buildSessionFactory();
        }

        /**
	 * Returns the SessionFactory used for this static class.
	 * 
	 * @return SessionFactory
	 */
	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	
}
